define(['jquery', 'bootstrap', 'backend', 'table' ,'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'member/actrelacc/index' + location.search,
                    add_url: 'member/actrelacc/add',
                    // edit_url: 'member/actrelacc/edit',
                    del_url: 'member/actrelacc/del',
                    multi_url: 'member/actrelacc/multi',
                    import_url: 'member/actrelacc/import',
                    table: 'activity_participants',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'activity_id', title: __('Activity_id')},
                        {field: 'account.username', title: __('Account.username'), operate: 'LIKE'},
                        {field: 'account.mobile', title: __('Account.mobile')},
                        {field: 'type_text', title: __('Type'), operate: false,formatter:function(value,row){
                                if (row['type'] == 1)
                                {
                                    return '<span style="color:yellowgreen">购买</span>';
                                }else if(row['type'] == 2) {
                                    return '<span style="color:black">添加</span>';
                                }else{
                                    return '<span style="color:black">未知</span>';
                                }
                            }
                        },
                        {
                            field: 'status',
                            title: __('Status') ,
                            visible:false,
                            formatter: Table.api.formatter.normal,
                            searchList: { '1': '购买','2': '添加'},
                        },
                        {field: 'createTime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {
                            field: 'operate',
                            title: __('Operate'),
                            // buttons: [
                            //     {
                            //         name: 'execute',
                            //         title: __('添加参与人'),
                            //         text: __('添加参与人'),
                            //         icon: 'fa fa-list',
                            //         classname: 'btn btn-info btn-xs btn-execute btn-dialog',
                            //          url: 'member/account/index?aid={account.aid}',
                            //         // callback: function (data) {
                            //         //     Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                            //         // }
                            //
                            //     },
                            // ],
                            table: table, events: Table.api.events.operate,
                            formatter:function (value,row,index){
                                var that = $.extend({}, this);
                                if(row['type'] ==1){
                                    $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit  - 删除按钮operate-del
                                }

                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                        }
                    ],
                ]
            });
            //
            $(document).on('click','.btn-spec_oper_btn', function () {
                var url = $(this).attr('data-url');
                var aid = $(this).attr('data-value');
                var msg = $(this).attr('data-title');
                if(!url) return false
                url = url +'?aid=' + aid;
//alert(aid);
                // var options = {
                //     url:url,
                //     type:'post',
                //     data:{aid:aid},
                // };
                Fast.api.open(url,msg);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);

        },


        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        spec_oper_btn: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});